package com.appkudos;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import android.app.Activity;
import android.os.Bundle;

import android.app.ListActivity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.provider.Browser;
import android.provider.Settings;

import android.provider.MediaStore.Audio.Media;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.SimpleAdapter.ViewBinder;

public class GroupConn extends Activity{
    ListView lv;
    Button joinGroupButton;
    Button createGroupButton;
	private Activity PARENTACTIVITY; 
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.group_view);
        PARENTACTIVITY = this;
        
        // get bookmark from database (values are from tutorial example)
        // create projection (define which columns to get)
        String[] projection = new String[] {Browser.BookmarkColumns._ID, 
        Browser.BookmarkColumns.TITLE, 
        Browser.BookmarkColumns.URL,
        Browser.BookmarkColumns.VISITS};
        
        // display title only
        String[] displayFields = new String[] {
        Browser.BookmarkColumns.TITLE};
  	  
        // get the int value of the textview field 
        int[] displayViews = new int[] {R.id.bmark_url};
        
        // get information from database 
  	    Cursor cur = managedQuery(android.provider.Browser.BOOKMARKS_URI, projection, null, null, null);
  	
  	    // get listview from layout
  	    lv=(ListView)findViewById(R.id.my_group_list);
  	  
  	    // link adapter to layout
        lv.setAdapter(new SimpleCursorAdapter(this, R.layout.friend_list, cur, displayFields, displayViews));

		lv.setOnItemClickListener(new OnItemClickListener() {
		    public void onItemClick(AdapterView<?> parent, View view,
		        int position, long id) {
		      // When clicked, show a toast with the TextView text
		//      Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
		//          Toast.LENGTH_SHORT).show();
		      Toast.makeText(getApplicationContext(), "list item at position "+position+" is clicked",
		      Toast.LENGTH_SHORT).show();
		    }
		});
		
        // enable filter on text
  	    lv.setTextFilterEnabled(true);
  	    
  	    // open a new page when add friend is clicked
  	     joinGroupButton = (Button) this.findViewById(R.id.b_join_group);
         joinGroupButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {     
              //   Intent intent = new Intent(PARENTACTIVITY, addFriend.class);
         	//	startActivity(intent);
            	   Toast.makeText(getApplicationContext(), "join group is clicked",
            			      Toast.LENGTH_SHORT).show();
             }
           });  	    // open a new page when add friend is clicked
  	   
         createGroupButton = (Button) this.findViewById(R.id.b_create_group);
         createGroupButton.setOnClickListener(new OnClickListener() {
             @Override
             public void onClick(View v) {     
              //   Intent intent = new Intent(PARENTACTIVITY, addFriend.class);
         	//	startActivity(intent);
            	   Toast.makeText(getApplicationContext(), "create group is clicked",
            			      Toast.LENGTH_SHORT).show();
             }
           });
         
         
   }
}
